#ifndef __RaySceneQuery_H__
#define __RaySceneQuery_H__

#include "video/Ray.h"
#include <vector>

namespace KEngine
{
class MovableObject;
class SceneManager;
struct RaySceneQueryResultEntry
{
	// Distance along the ray
	float distance;
	// The movable, or NULL if this is not a movable result
	MovableObject* movable;
	// Comparison operator for sorting
	bool operator < (const RaySceneQueryResultEntry& rhs) const
	{
		return this->distance < rhs.distance;
	}
};
typedef std::vector<RaySceneQueryResultEntry> RaySceneQueryResult;

class RaySceneQuery
{
public:
	RaySceneQuery(SceneManager* mgr);
	virtual ~RaySceneQuery();

	virtual void setRay(const Ray& ray);
	virtual const Ray& getRay() const;
	virtual void setSortByDistance(bool sort, unsigned short maxresults = 0);
	virtual bool getSortByDistance() const;
	virtual unsigned short getMaxResults() const;

	virtual RaySceneQueryResult& execute();
	virtual RaySceneQueryResult& getLastResults();
	virtual void clearResults();
	virtual bool queryResult(MovableObject* obj, float distance);

protected:
	Ray						mRay;
	bool					mSortByDistance;
	unsigned short			mMaxResults;
	SceneManager*			mParentSceneMgr;
	RaySceneQueryResult		mResult;
};

}
#endif 